package com.cy.common.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.lang.annotation.Target;

@Component
@Aspect
public class SysTimeAspect {
    @Pointcut("bean(userServcieImpl)")
    public void doTime(){}

    @Before("doTime()")
    public void doBefore(){
        System.out.println("time before");
    }
    @After("doTime()")
    public void doAfter(){
        System.out.println("time After");
    }
    @AfterReturning("doTime()")
    //在多个切面标签执行时，业务结束之后，有after先执行，然后执行AfterReturning
    public void doTarget(){
        System.out.println("time AfterReturning");
    }
    @AfterThrowing("doTime()")
    //切面业务出现异常执行After,然后继续执行AfterThrowing
    public void doAfterThrowing(){
        System.out.println("time AfterThrowing");
    }
    @Around("doTime()")//@Around是主切面方法，核心写在此处
    //ProceedingJoinPoint这个参数，代表对应的切面类中执行的方法
    public Object doAround(ProceedingJoinPoint pj)
        throws Throwable{
        System.out.println("doAround.before");
        try {
            Object obj=pj.proceed();
            System.out.println("doAround.after");
            return obj;
        }catch (Throwable e){
            System.out.println(e.getMessage());
            throw e;
        }

    }



}
